#include <iostream>
#include <string>
#include <cassert>
#include "sqlite.hpp"
using namespace std;


int select_stu_callback(void* arg, int clo_count, char** result, char** fields_name) {
    vector<string>* names = static_cast<vector<string>*>(arg);
    names->push_back(result[0]);
    names->back() += "|";
    names->back() += result[1];
    names->back() += "|";
    names->back() += result[2];
    return 0;
}

int main() {
    SqliteHelper helper("./test.db");
    
    // 1、创建或打开库文件
    assert(helper.open());

    // 2、创建表(表不存在则创建)
    const char* create_table = "create table if not exists student (id int primary key, name varchar(32) not null, age int);";
    assert(helper.execute(create_table, nullptr, nullptr));
    // 3、新增、修改、删除、查询
    // const char* insert_info = "insert into student (id, name, age) values(2, '小红', 20), (3, '小七', 23), (4, '小张', 12);";
    // assert(helper.execute(insert_info, nullptr, nullptr));

    // 修改
    // const char* modify_info = "update student set name='张晓明' where id=1;";
    // helper.execute(modify_info, nullptr, nullptr);

    // 删除
    // const char* delete_info = "delete from student where id=2;";
    // helper.execute(delete_info, nullptr, nullptr);
    // 查询
    vector<string> names; // 查询的结果放到vector里面
    const char* select_info = "select id, name, age from student;";
    helper.execute(select_info, select_stu_callback, &names);
    for (auto& name : names) {
        cout << name << endl;
    }
    //4、关闭数据库
    helper.close();
    return 0;
}